<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 400px;
            border-bottom: 1px solid #ccc;
            margin: 100px auto;
        }
        .box input{
            width: 370px;
            height: 30px;
            border: 0;
            outline: none;
        }
        .box img{
            position: relative;
            top: 0;
            left: 380px;
            width: 12px;
        }
    </style>
</head>
<body>
    <div class="box">
        <label for="">
            <img src="img/up.jpg" alt="" id="eye">
        </label>
        <input type="password" placeholder="密码" id="pwd">
    </div>
    <script>
        //1.获取元素
        var pwd = document.getElementById('pwd');
        var eye = document.getElementById('eye');
        //2.注册事件 处理程序
        var flag = 1;
        eye.onclick = function () {
            if (flag == 1){
                pwd.type ='text';
                eye.src = 'img/down.jpg';
                flag = 0;//赋值操作
            }else {
                pwd.type = 'password';
                eye.src = 'img/up.jpg';
                flag = 1;
            }

        }
    </script>
</body>
</html>